package temp.lho.lws.controller.exception;

import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import temp.lho.lws.emum.MsgStatusEmum;
import temp.lho.lws.result.ResultBody;

/**
 * @author liuws
 * @create 2020-07-01 13:48
 */
@RestControllerAdvice
public class MyException {

    @ExceptionHandler(RuntimeException.class)
    public ResultBody handlerExcetion(RuntimeException e) {
        String msg = e.getMessage();
        Integer code = -1;
        if (e instanceof UnknownAccountException || e instanceof IncorrectCredentialsException) {
            msg = MsgStatusEmum.USER_LOGIN_NAME_ERROR_MSG.getMsg();
            code = MsgStatusEmum.USER_LOGIN_NAME_ERROR_MSG.getCode();
        }
        return ResultBody.toResultBody(code, msg);
    }

}
